package com.tiger.transaction.sample2;

import javax.naming.InitialContext;

public class Sample2Bean implements javax.ejb.SessionBean {
	private javax.ejb.SessionContext sessionContext = null;

	public void setSessionContext(javax.ejb.SessionContext sessionContext) {
		this.sessionContext = sessionContext;
	}

	public void ejbCreate() {
	}

	public void test1() {
		try {
			InitialContext ctx = new InitialContext();
			javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/Database");
			java.sql.Connection con = ds.getConnection();
			java.sql.Statement stmt = con.createStatement();

			javax.transaction.UserTransaction ut = sessionContext.getUserTransaction();
			ut.begin();
			java.sql.ResultSet rs = stmt.executeQuery("SELECT FLIGHTNO, SEATNO, CUSTOMERNAME FROM FLIGHTBOOKING");
			stmt.close();
			con.close();
		} catch (javax.naming.NamingException e) {
			throw new javax.ejb.EJBException(e);
		} catch (java.sql.SQLException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.NotSupportedException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.SystemException e) {
			throw new javax.ejb.EJBException(e);
		}
	}

	public void test2() {
		try {
			InitialContext ctx = new InitialContext();
			javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/Database");
			java.sql.Connection con = ds.getConnection();
			java.sql.Statement stmt = con.createStatement();

			java.sql.ResultSet rs = stmt.executeQuery("SELECT FLIGHTNO, SEATNO, CUSTOMERNAME FROM FLIGHTBOOKING");
			stmt.close();
			con.close();
		} catch (javax.naming.NamingException e) {
			throw new javax.ejb.EJBException(e);
		} catch (java.sql.SQLException e) {
			throw new javax.ejb.EJBException(e);
		}
	}

	public void test3() {
		try {
			InitialContext ctx = new InitialContext();
			javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/Database");
			java.sql.Connection con = ds.getConnection();
			java.sql.Statement stmt = con.createStatement();

			java.sql.ResultSet rs = stmt.executeQuery("SELECT FLIGHTNO, SEATNO, CUSTOMERNAME FROM FLIGHTBOOKING");
			javax.transaction.UserTransaction ut = sessionContext.getUserTransaction();
			ut.commit();
			stmt.close();
			con.close();
		} catch (javax.naming.NamingException e) {
			throw new javax.ejb.EJBException(e);
		} catch (java.sql.SQLException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.RollbackException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.SystemException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.HeuristicMixedException e) {
			throw new javax.ejb.EJBException(e);
		} catch (javax.transaction.HeuristicRollbackException e) {
			throw new javax.ejb.EJBException(e);
		}
	}

	public void ejbActivate() {
	}

	public void ejbPassivate() {
	}

	public void ejbRemove() {
	}
}
